// src/styles/originTheme.js
export const originTheme = {
  // 颜色配置（Origin经典色板）
  color: [
    '#000000', '#FF0000', '#0000FF', '#FF00FF',
    '#00FF00', '#00FFFF', '#FFB300', '#803380'
  ],
  
  // 全局文字样式
  textStyle: {
    fontFamily: 'Arial, Helvetica, sans-serif',
    fontSize: 16,
    color: '#000000'
  },
  
  // 坐标轴样式
  axis: {
    line: {
      lineStyle: {
        color: '#000000',
        width: 1,
        type: 'solid'
      }
    },
    axisTick: {
      show: true,
      length: 6,
      lineStyle: {
        color: '#000000',
        width: 1
      }
    },
    axisLabel: {//设置坐标轴标签的样式。
      show: true,
      margin: 8,
      fontSize: 16,
      color: '#000000',
      fontFamily: 'Arial'
    },
    splitLine: {
      show: true,
      lineStyle: {
        color: '#000000',
        width: 1,
        type: 'solid',
        opacity: 0.2
      }
    },
    minorTick: {
      show: true,
      splitNumber: 2,
      length: 3,
      lineStyle: {
        color: '#000000',
        width: 1
      }
    },
    minorSplitLine: {
      show: false
    }
  },
  
  // 图例样式
  legend: {
    show: true,
    textStyle: {
      fontSize: 14,
      fontFamily: 'Arial',
      color: '#000000'
    },
    itemGap: 15,
    itemWidth: 30,
    itemHeight: 14,
    borderWidth: 0,
    padding: [5, 10]
  },
  
  // 网格样式
  grid: {
    show: true,
    containLabel: true,
    left: '10%',
    right: '5%',
    top: '8%',
    bottom: '12%',
    backgroundColor: '#ffffff',
    borderColor: '#000000',
    borderWidth: 1
  },
  
  // 线图样式
  line: {
    symbol: 'circle',
    symbolSize: 7,
    lineStyle: {
      width: 1,
      type: 'solid'
    },
    emphasis: {
      lineStyle: {
        width: 2
      },
      symbolSize: 9
    },
    smooth: false,
    connectNulls: false
  },
  
  // 散点图样式
  scatter: {
    symbol: 'circle',
    symbolSize: 7,
    itemStyle: {
      borderWidth: 1,
      borderColor: '#000000'
    },
    emphasis: {
      symbolSize: 9,
      itemStyle: {
        borderWidth: 2
      }
    }
  },
  
  // 柱状图样式
  bar: {
    barWidth: '50%',
    barGap: '30%',
    itemStyle: {
      borderWidth: 1,
      borderColor: '#000000'
    },
    emphasis: {
      itemStyle: {
        borderWidth: 2
      }
    }
  },

  // 标题样式
  title: {
    textStyle: {
      fontSize: 16,
      fontWeight: 'normal',
      fontFamily: 'Arial',
      color: '#000000'
    },
    padding: [10, 10]
  },

  // 工具提示样式
  tooltip: {
    trigger: 'item',
    backgroundColor: '#ffffff',
    borderColor: '#000000',
    borderWidth: 1,
    textStyle: {
      color: '#000000',
      fontSize: 14,
      fontFamily: 'Arial'
    },
    axisPointer: {
      type: 'cross',
      lineStyle: {
        color: '#000000',
        width: 1,
        type: 'dashed'
      },
      crossStyle: {
        color: '#000000',
        width: 1,
        type: 'dashed'
      },
      label: {
        backgroundColor: '#000000',
        color: '#ffffff'
      }
    }
  }
};

// 应用Origin风格到图表选项
export const applyOriginStyle = (options, darkMode = false) => {
  const enhancedOptions = {
    ...options,
    grid: {
      ...originTheme.grid,
      ...(options.grid || {})
    },
    xAxis: Array.isArray(options.xAxis) 
      ? options.xAxis.map(axis => ({
          ...originTheme.axis,
          ...axis
        }))
      : {
          ...originTheme.axis,
          ...options.xAxis
        },
    yAxis: Array.isArray(options.yAxis) 
      ? options.yAxis.map(axis => ({
          ...originTheme.axis,
          ...axis
        }))
      : {
          ...originTheme.axis,
          ...options.yAxis
        },
    series: options.series?.map(series => {
      const baseStyle = originTheme[series.type] || {};
      return {
        ...baseStyle,
        ...series
      };
    }) || []
  };
  
  // 黑暗模式支持
  if (darkMode) {
    enhancedOptions.backgroundColor = '#1E1E1E';
    enhancedOptions.textStyle = {
      ...enhancedOptions.textStyle,
      color: '#EEE'
    };
    
    // 修改坐标轴样式
    const darkAxisStyle = {
      axisLine: {
        lineStyle: { color: '#CCC' }
      },
      axisTick: {
        lineStyle: { color: '#CCC' }
      },
      axisLabel: {
        color: '#EEE'
      },
      splitLine: {
        lineStyle: { color: '#333' }
      }
    };

    // 处理 x 轴
    if (Array.isArray(enhancedOptions.xAxis)) {
      enhancedOptions.xAxis = enhancedOptions.xAxis.map(axis => ({
        ...axis,
        ...darkAxisStyle
      }));
    } else {
      enhancedOptions.xAxis = {
        ...enhancedOptions.xAxis,
        ...darkAxisStyle
      };
    }

    // 处理 y 轴
    if (Array.isArray(enhancedOptions.yAxis)) {
      enhancedOptions.yAxis = enhancedOptions.yAxis.map(axis => ({
        ...axis,
        ...darkAxisStyle
      }));
    } else {
      enhancedOptions.yAxis = {
        ...enhancedOptions.yAxis,
        ...darkAxisStyle
      };
    }

    // 修改图例样式
    if (enhancedOptions.legend) {
      enhancedOptions.legend = {
        ...enhancedOptions.legend,
        textStyle: {
          ...enhancedOptions.legend.textStyle,
          color: '#EEE'
        }
      };
    }

    // 修改标题样式
    if (enhancedOptions.title) {
      enhancedOptions.title = {
        ...enhancedOptions.title,
        textStyle: {
          ...enhancedOptions.title.textStyle,
          color: '#EEE'
        }
      };
    }
  }
  
  return enhancedOptions;
};